package cn.edu.scau.cmi.linhongyu.hibernate;
	import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.linhongyu.hibernate.dao.StudentDAO;
import cn.edu.scau.cmi.linhongyu.hibernate.dao.TeacherDAO;
import cn.edu.scau.cmi.linhongyu.hibernate.domain.Student;
import cn.edu.scau.cmi.linhongyu.hibernate.domain.Teacher;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;


public class hibernateController {
	StudentDAO studentDAO = new StudentDAO();
	TeacherDAO teacherDAO = new TeacherDAO();
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button creatStudent;

    @FXML
    private Button createTeacher;

    @FXML
    private Button listStudent;

    @FXML
    private Button listTeacher;

    @FXML
    private TextArea msg;

    @FXML
    private Button setTeacher;

    @FXML
    private TextField studentName;

    @FXML
    private TextField teacherName;


    @FXML
    void creatStudent(ActionEvent event) {
    	Student student = new Student();
    	student.setName(studentName.getText());
    	studentDAO.save(student);
    	msg.setText("添加学生成功");
    }

    @FXML
    void createTeacher(ActionEvent event) {
    	Teacher teacher=new Teacher();
    	teacher.setName(teacherName.getText());
		teacherDAO.save(teacher);
		msg.setText("添加学生成功");
    }

    @FXML
    void listStudent(ActionEvent event) {
    	msg.setText(null);
    	List Students = studentDAO.findAll();
		Iterator<?> StudentIterator = Students.iterator();
		while(StudentIterator.hasNext()){
			Student Student = (Student) StudentIterator.next();
			msg.appendText(Student.getName()+'\n');
		}
    }

    @FXML
    void listTeacher(ActionEvent event) {
    	msg.setText(null);
    	List Teachers = teacherDAO.findAll();
		Iterator<?> TeacherIterator = Teachers.iterator();
		while(TeacherIterator.hasNext()){
			Teacher Teacher = (Teacher) TeacherIterator.next();
			msg.appendText(Teacher.getName()+'\n');
		}
    }

    @FXML
    void setTeacher(ActionEvent event) {
    	
    }

    @FXML
    void initialize() {
        assert creatStudent != null : "fx:id=\"creatStudent\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert createTeacher != null : "fx:id=\"createTeacher\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert listStudent != null : "fx:id=\"listStudent\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert listTeacher != null : "fx:id=\"listTeacher\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert msg != null : "fx:id=\"msg\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert setTeacher != null : "fx:id=\"setTeacher\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert studentName != null : "fx:id=\"studentName\" was not injected: check your FXML file 'hibanate.fxml'.";
        assert teacherName != null : "fx:id=\"teacherName\" was not injected: check your FXML file 'hibanate.fxml'.";


    }
    

}
